/**
 * 
 */
package demo.tellurium.test;

import java.util.HashMap;
import java.util.Map;

import org.junit.BeforeClass;
import org.junit.Test;

import demo.tellurium.framework.BaseTelluriumJUnitTestCase;
import demo.tellurium.module.DoubanModule;

/**
 * @author roger.xu
 * 
 */
public class DoubanJUnitTestCase extends BaseTelluriumJUnitTestCase {

    private static DoubanModule douban;

    @BeforeClass
    public static void initUi() {
        douban = new DoubanModule();
        douban.defineUi();
    }

    @Test
    public void connectTo() {
        final String id = "toy"; // face, toy, love

        final String pageIdKey = String.format("douban.online.id.%s", id);
        final String pageId = getProperty(pageIdKey);
        final String pagePathPattern = getProperty("douban.online.path.pattern");
        final String pagePath = String.format(pagePathPattern, pageId);
        final String contextUrl = getProperty("douban.context.url");
        final String url = String.format("%s/%s", contextUrl, pagePath);
        connectUrl(url);
    }

    @Test
    public void testLink() {
        console.debug("[testLink]");
        douban.goMainPage();
    }

    @Test
    public void testFindUser() {
        console.debug("[testFindUser]");
        final int startPageNum = 0;
        doJumpToPage(startPageNum);

        Map<String, Object> settings = new HashMap<String, Object>();
        settings.put("isFindAll", Boolean.TRUE);

        douban.findUser("ice", settings);
        //douban.getResults();
    }

    private void doJumpToPage(int pageNum) {
        if (pageNum > 0) {
            int pageSize = douban.pageSize;
            String photoAlbumUrl = douban.photoAlbumUrl;
            int start = pageSize * (pageNum - 1);
            String pageUrl = String.format("%s?start=%d", photoAlbumUrl, start);
            connectUrl(pageUrl);
        }
    }
}
